package com.atguigu.es.client;

import io.searchbox.action.Action;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;

import java.io.IOException;

/**
 * Created by Smexy on 2022/5/21
 *
 *      JestClient: 客户端对象
 *
 *              构造：
 *                          new 构造器()
 *                  设计模式:
 *                          工厂模式 :    A a= new AFactory().getA()
 *                          建造者模式：   A a = new ABuilder().build()
 *
 *       Action: 要执行的命令
 *              读: Search
 *
 *              写:  Index
 *                   Delete
 *
 *              批量写： Bulk
 */
public class GeneralProcessDemo {

    public static void main(String[] args) throws IOException {

        //创建客户端
        JestClientFactory jestClientFactory = new JestClientFactory();

        // 连接server端
        HttpClientConfig httpClientConfig = (new HttpClientConfig.Builder("http://hadoop102:9200")).build();

        jestClientFactory.setHttpClientConfig(httpClientConfig);

        JestClient jestClient = jestClientFactory.getObject();

        // 准备操作的命令
        Action a=null;

        // 执行命令
        jestClient.execute(a);

        // 如果是读，解析server返回的结果

        // 关闭客户端
        jestClient.close();

    }


}
